package com.skyolder.milkbee.web.rest.pub;

import java.net.URISyntaxException;
import java.util.List;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.codahale.metrics.annotation.Timed;
import com.skyolder.milkbee.domain.Area;
import com.skyolder.milkbee.service.AreaService;

/**
 * REST controller for managing Area.
 */
@RestController("pubAreaResource")
@RequestMapping("/api/pub")
public class AreaResource {

    private final Logger log = LoggerFactory.getLogger(AreaResource.class);
        
    @Inject
    private AreaService areaService;





    @GetMapping("/areas/provinces")
    @Timed
    public ResponseEntity<List<Area>> getAllProvinces()
        throws URISyntaxException {
        log.debug("REST request to get a page of Areas");
        List<Area> list = areaService.findByRankAndParent(1,0);
        return new ResponseEntity<>(list, HttpStatus.OK);
    }
    @GetMapping("/areas/cities/{province}")
    @Timed
    public ResponseEntity<List<Area>> getAllCities(@PathVariable long province)
    		throws URISyntaxException {
    	log.debug("REST request to get a page of Areas");
    	List<Area> list = areaService.findByRankAndParent(2,province);
    	return new ResponseEntity<>(list, HttpStatus.OK);
    }
    @GetMapping("/areas/counties/{city}")
    @Timed
    public ResponseEntity<List<Area>> getAllCounties(@PathVariable long city)
    		throws URISyntaxException {
    	log.debug("REST request to get a page of Areas");
    	List<Area> list = areaService.findByRankAndParent(3,city);
    	return new ResponseEntity<>(list, HttpStatus.OK);
    }
}